
//
//  Extension + UIButton.swift
//  SinaMicroBlogSwift2
//
//  Created by dqw on 15/8/3.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(title: String, imageName: String?, fontSize: CGFloat = 12, color: UIColor = UIColor.darkGrayColor()) {
        
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        if let image = imageName {
            setImage(UIImage(named: imageName!), forState: UIControlState.Normal)
        }
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: UIControlState.Normal)
        sizeToFit()
        
    }
    
    
    convenience init(imageName: String?) {
        self.init()
        
        setImage(imageName)
        
    }
    
    func setImage(name: String?) {
        
        setImage(UIImage(named: name!), forState: UIControlState.Normal)
        setImage(UIImage(named: name! + "_highlighted"), forState: UIControlState.Highlighted)
        contentEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
        imageView?.contentMode = UIViewContentMode.ScaleAspectFill
        sizeToFit()
    }
}
